#!/bin/sh

echo -n "KERNEL_VERSION=" > make.inc
cat version >> make.inc
rm make.deps 2>/dev/null

echo "configure will compile tools and set build variables based on"
echo "which sytem type it detects."

echo -e -n "compiling tools..."
gcc -std=c99 tools/make_initrd.c -O3 -o tools/mkird 
printf "done\nprocessing configuration...\n"

if ! which ruby > /dev/null; then
	echo "*** Ruby wasn't found on your system. It's fine, but you will need to"
	echo "*** provide your own config files, and generate the initrd manually."
fi

SYSNAME=""

if [ -e /proc/seaos ]; then
	SYSNAME="seaos"
else
	SYSNAME="linux"
fi

echo -ne "It would appear that you're running $SYSNAME, but let's make sure.\nWhat OS are you running (seaos/linux)? [$SYSNAME] "
read inp

if [ "$inp" != "" ]; then
	SYSNAME=$inp
fi

if [ "$SYSNAME" == "seaos" ]; then
	echo "SYSNAME=seaos" >> make.inc
	echo "CC=gcc" >> make.inc
	echo "LD=ld" >> make.inc
	echo "AR=ar" >> make.inc
else
	echo "SYSNAME=linux" >> make.inc
	echo "CC=i586-pc-seaos-gcc" >> make.inc
	echo "LD=i586-pc-seaos-ld" >> make.inc
	echo "AR=i586-pc-seaos-ar" >> make.inc
fi

echo "ARCH=x86" >> make.inc
echo "export ARCH" >> make.inc

echo "Allgood" > tools/confed

cat > initrd.conf <<EOF
# default ramdisk listing for seaos
# fileformat is local-file:initrd-file.

data-initrd/usr/sbin/fsck       : /usr/sbin/fsck
data-initrd/usr/sbin/fsck.ext2  : /usr/sbin/fsck.ext2
data-initrd/preinit.sh          : /preinit.sh
data-initrd/etc/fstab           : /etc/fstab
data-initrd/bin/bash            : /sh
data-initrd/bin/modprobe        : /modprobe
data-initrd/bin/mount           : /mount
data-initrd/bin/chroot          : /chroot

drivers/built/ata               : /ata
drivers/built/ext2			    : /ext2
drivers/built/pci			    : /pci
drivers/built/keyboard			: /keyboard
drivers/built/partitions		: /partitions

EOF


echo "okay! all done!"
